<template>
  <el-dialog
    title="提现记录"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    width="1000px"
    :before-close="cancel"
  >
    <el-row class="mb8">
      <el-date-picker
        @change="getList"
        clearable
        :start-placeholder="$t('开始时间')"
        :end-placeholder="$t('结束时间')"
        v-model="queryParams.time"
        size="small"
        type="daterange"
        value-format="yyyy-MM-dd"
      />
      <el-button @click="getList" size="mini" style="margin: 0 5px" type="primary"> {{ $t('搜索') }}</el-button>
    </el-row>
    <el-table :height="calTableHeight() - 50" v-loading="loading" ref="WithdrawalRecord" :data="tableData">
      <el-table-column align="center" show-overflow-tooltip width="350" :label="$t('提现日期范围')">
        <template slot-scope="{ row }">
          <span>{{ row.withdrawStartTime }}</span
          >至
          <span>{{ row.withdrawEndTime }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="amount" :label="$t('提现金额')">
        <template slot-scope="{ row }">
          <span>{{ row.amount | thousand }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="" :label="$t('是否汇款')">
        <template slot-scope="{ row }">
          <span :style="{ color: '#1890ff' }" v-if="row.isRemit == 1">是</span>
          <span :style="{ color: 'red' }" v-if="row.isRemit == 0">否</span>
        </template>
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="createTime" :label="$t('创建时间')">
      </el-table-column>
      <el-table-column align="center" show-overflow-tooltip prop="afterFunds" :label="$t('操作')">
        <template slot-scope="{ row }">
          <el-popconfirm
            v-hasPermi="['distribution:billDistributorWithdraw:remit']"
            v-show="!row.isRemit"
            confirm-button-text="已汇款"
            cancel-button-text="没有汇款"
            @confirm="submitForm(row)"
            icon="el-icon-info"
            icon-color="red"
            title="是否已经汇款?"
          >
            <el-button slot="reference" type="text" size="mini">去汇款</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer">
      <el-button @click="cancel">关闭 </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { billDistributorWithdrawList, billDistributorWithdraw } from '@/api/bill/distributerBalance'
export default {
  activated() {
    this.$nextTick(() => this.$refs['WithdrawalRecord']?.doLayout())
  },
  props: {
    formData: {
      type: Object,
      default: () => {
        return {}
      },
    },
    /**
     * data
     */
    data: {
      type: Array,
      default: () => [],
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      loading: false,
      /**总条数 */
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        time: [],
      },
      form: {},
      tableData: [],
    }
  },
  watch: {
    show: function (newValue) {
      if (newValue) {
        if (newValue) {
          this.getList()
        }
      }
    },
  },
  methods: {
    getList() {
      const time = this.queryParams.time || []
      const data = {
        ...this.queryParams,
        withdrawStartTime: time[0],
        withdrawEndTime: time?.[1],
      }
      delete data.time

      this.loading = true
      billDistributorWithdrawList({ distrId: this.formData.distrId, ...data }).then((res) => {
        this.tableData = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    submitForm(data) {
      billDistributorWithdraw({ id: data.id }).then((res) => {
        this.$message({
          type: 'success',
          message: res.msg,
        })
        this.getList()
      })
    },
    cancel() {
      this.$emit('getList')
      this.$emit('update:show', false)
    },
  },
}
</script>
<style scoped lang="scss"></style>
